<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close closeBtn" ></button>
            <h4 class="modal-title">选择文件</h4>
        </div>
        <div class="navbar navbar-default" role="navigation" style="margin-bottom:0">
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav">
                    <li class="active tags" data-id="1">
                        <a href="#" >
                            预归档
                        </a>
                    </li>
                    <li class="tags" data-id="2">
                        <a href="#" >
                            档案库
                        </a>
                    </li>
                    <li class="tags" data-id="3">
                        <a href="#" >
                            编研库
                        </a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="modal-body">
            <form class="modalForm form-horizontal" action="{:url('index/Count/setFile')}" method="post">
                <input type="hidden" name="cate_id" class="cate_id" value="">
                <div class="portlet green box ">
                    <div class="portlet-title">
                        <div class="caption">
                            <i class="fa fa-cogs"></i>目录
                        </div>
                    </div>
                    <div class="portlet-body showTree">
                        <div id="tree_5" class="tree-demo" >
                            {$tree}
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn default model1close" data-dismiss="modal">关闭</button>
            <button type="button" class="btn blue save">保存</button>
        </div>
    </div>
</div>


<script>
    // App.init();
    // UITree.init();
    upTree('tree_5');
    $('.closeBtn').click(function () {
        $('#model2').modal('hide');
        $('#model3').modal('hide');
        return false;
    });
    $('.guidf').click(function () {
        $('#model2').modal('show');
    });
    $('.guidp').click(function () {
        $('#model3').modal('show');
    });
    var cid;
    $('.navbar-nav li').click(function () {
        var $this = $(this);
        var id = $this.attr('data-id');

        if(id == 1){cid = -1}
        else if(id == 2){cid = -2}
        else{cid = -3}
        console.log(cid);
        $.ajax({
            url:'{:url(\'index/Borrows/getTree\')}',
            data:{cate_type:id},
            dataType:'json',
            type:'post',
            success:function (e) {
                if(e.code == 1) {
                    $('.showTree').html('<div id="tree_4" class="tree-demo" >'+e.data+'</div>');
                    getArc(cid);
                }else{
                    $('.showTree').html('<div id="tree_4" class="tree-demo" >'+e.msg+'</div>');
                }
                $('.navbar-nav li').removeClass('active');
                $this.addClass('active');
                setTimeout(function () {
                    upTree('tree_4');
                    $("#tree_4").on('changed.jstree', function (e, data) {
                        var id = data.node.data.id;
                        $('.cate_id').val(id);
                    });
                },100);
            }
        });
    });
    //进来 预归档根目录文件
    // getArc(-1);
    $('.bor_time_limit').val('{$date}');
    $("#tree_5").on('changed.jstree', function (e, data) {
        var id = data.node.data.id;
        $('.cate_id').val(id);
        // getArc(id);

    });

    /*$("#tree_1").on('changed.jstree', function (e, data) {
        var id = data.node.data.id;
        $.ajax({
            url:'{:url(\'index/File/getPathById\')}',
            data:{id:id},
            dataType:'json',
            type:'post',
            success:function (e) {
                $('.interfile_cate_id').val(id);
                $('.guidp').val(e.data);
                $('#model3').modal('hide');
            }
        });


    });*/
    function getArc(id) {
        $.ajax({
            url:'{:url(\'index/File/getArcByCateId\')}',
            data:{id:id},
            dataType:'json',
            type:'post',
            success:function (e) {
                if(e.code == 1) {
                    $('.tbody').html(e.data);
                    $('.editBtn').click(function () {
                        var aid = $(this).attr('data-id');
                        var aname = $(this).attr('data-name');
                        $('.guidf').val(aname);
                        $('.arc_id').val(aid);
                        $('#model2').modal('hide');
                    });
                }else{
                    $('.tbody').html('');
                }
            }
        });
    }

    function upTree(id) {
        $('#'+id).jstree({
            "core" : {
                "themes" : {
                    "responsive": false
                }
            },
            "types" : {
                "default" : {
                    "icon" : "fa fa-folder icon-warning icon-lg"
                },
                "file" : {
                    "icon" : "fa fa-file icon-warning icon-lg"
                }
            },
            "plugins": ["types"]
        });
    }
    dt().modalSave();
</script>